package com.dongdongshop.controller;

import com.dongdongshop.bo.AlipayOrderBO;
import com.dongdongshop.bo.OrderBO;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.service.OrderService;
import com.dongdongshop.util.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("order")
public class OrderController {

    @DubboReference
    private OrderService orderService;

    @RequestMapping("show")
    public String show(){
        return "getOrderInfo";
    }

    //提交订单
    @RequestMapping("submitOrder")
    @ResponseBody
    public Result submitOrder() {
        //先获取登录用户id
        TbUser user = (TbUser) SecurityUtils.getSubject().getPrincipal();
        AlipayOrderBO order = orderService.createOrder(user.getId());
        return Result.OK().setData(order);
    }

    //查询
    @RequestMapping("getAll")
    @ResponseBody
    public Result getAll(){
        TbUser user = (TbUser) SecurityUtils.getSubject().getPrincipal();
        List<OrderBO> all = orderService.getAll(user.getId());
        return Result.OK().setData(all);
    }
}
